<%--
  Created by IntelliJ IDEA.
  User: 杨飞龙
  Date: 2020/5/31
  Time: 0:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<!DOCTYPE HTML>
<html>
<head>
    <!-- 设置页面的 基本路径，页面所有资源引入和页面的跳转全部基于 base路径 -->
    <base href="<%=basePath%>">

    <link rel="stylesheet" type="text/css" href="lib/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="lib/easyui/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="lib/z-tree/css/zTreeStyle/zTreeStyle.css">


    <%--js--%>
    <script type="text/javascript" src="lib/easyui/jquery.min.js">
    </script>
    <script type="text/javascript" src="lib/easyui/jquery.easyui.min.js">
    </script>
    <script type="text/javascript" src="lib/z-tree/js/jquery.ztree.all.js"></script>
    <script type="text/javascript" src="lib/easyui/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="lib/jquery.serializejson/jquery.serializejson.min.js"></script>
</head>
<body>

<%--添加账号--%>
<div id="addMarriedWindow" class="easyui-window" title="添加账号" style="width:500px;height:500px"
     data-options="modal:true,closed:true">

    <form id="marriedForm" method="post">
        <input type="hidden" name="pid">
        <div style="padding: 10px 50px">
            <input required class="easyui-textbox" prompt="请输入您的姓名："
                   data-options="missingMessage:'公司名称不能为空',label:'姓名：'"
                   style="width:100%;height:30px;padding:10px" name="pname" >
        </div>
        <div style="padding: 10px 50px">
            <input required class="easyui-passwordbox" prompt="请输入密码" iconWidth="28"
                   style="width:100%;height:30px;padding:10px" id="ppwd"
                   data-options="showEye:false,missingMessage:'密码不能为空',label:'密码：'"
                   name="ppwd">
        </div>
        <div style="padding: 10px 50px">
            <input  class="easyui-passwordbox" prompt="请再次输入密码" iconWidth="28"
                   style="width:100%;height:30px;padding:10px"
                   data-options="showEye:false,missingMessage:'密码不能为空',label:'确认密码：'"
                   required="required" validType="equals['#ppwd']" invalidMessage="两次输入密码不匹配"
                   >
        </div>
        <div style="padding: 10px 50px">
            <input required class="easyui-textbox" prompt="请输入您的手机号" iconWidth="28"
                   style="width:100%;height:30px;padding:10px"
                   data-options="label:'手机号：'"
                   name="phone" >
        </div>
        <div style="padding: 10px 50px">
            <input required class="easyui-textbox" prompt="请输入您的邮箱" iconWidth="28"
                   style="width:100%;height:30px;padding:10px"
                   data-options="label:'邮箱：',validType:'email' ,invalidMessage:'邮箱格式不正确'"
                   name="pmail">
        </div>

        <div style="padding: 10px 50px">
            <input  required class="easyui-datebox" name="marrydate" data-options="label:'婚期：'"
                    style="width:100%;height:30px;padding:10px">
        </div>

        <div style="padding: 15px 50px;text-align: center">
            <a onclick="insertMarried()" href="javascript:void(0)" class="easyui-linkbutton">提交</a>
        </div>

    </form>
</div>



<%--条件搜索框--%>
<div id="tb" style="padding:2px 5px;">
    <form id="marriedSearchForm" action="married/list.do">
        <input class="easyui-textbox" name="pname" prompt="新人姓名" style="width:110px">
        <input class="easyui-textbox" name="phone" prompt="新人手机号" style="width:110px">
        <a href="javascript:void(0)" onclick="searchMarried()" class="easyui-linkbutton" iconCls="icon-search">搜索</a>
    </form>
</div>

<%--linkenbutton--%>
<div id="tt" style="padding:5px 0;">
    <a id="marriedAdd"  href="javascript:void(0)" class="easyui-linkbutton"
       data-options="iconCls:'icon-add'">添加</a>
    <a id="delMarried" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove'">删除</a>
    <a id="editMarried" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove'">编辑</a>
    <a id="status" href="javascript:void(0)" class="easyui-linkbutton"
       iconCls="icon-clear"><span
            id="status_sp">禁用启用账号</span></a>
</div>

<table id="dataTabs" style="height:500px"></table>


<script type="text/javascript">


    $(function () {
        $('#dataTabs').datagrid({
            url: 'married/list.do',
            fit: true,
            fitColumns: true,
            pagination: true,//分页条
            checkOnSelect: false,
            striped: true,
            toolbar: '#tt',//顶部工具栏
            header: '#tb',
            columns: [[

                {field: '', checkbox: true},
                {field: 'pid', title: '编号'},
                {field: 'pname', title: '姓名', width: 100},
                {field: 'phone', title: '手机号', width: 100},
                {field: 'pmail', title: '邮箱', width: 100},
                {
                    field: 'regdate', title: '注册时间', width: 100, formatter(value, row, index) {
                        return value.year + '-' + value.monthValue + '-' + value.dayOfMonth
                    }
                },
                {
                    field: 'status', title: '账号状态', width: 100, formatter: function (value, row, index) {

                        if (value == 0) {
                            return "<span style='color: red'>禁用</span>"
                        }
                        if (value == 1) {
                            return "<span >正常</span>"
                        }
                    }
                }
            ]],
            onCheck:function (index,row) {
                var comStatus = row.status;

                if (comStatus == 0) {
                    $("#status_sp").text("账号启用")
                }
                if (comStatus == 1) {
                    $("#status_sp").text("账号禁用")
                }
            }
        });
    })
</script>


<script type="text/javascript">
    //条件搜索
    function searchMarried() {
        var formData = $("#marriedSearchForm").serializeJSON();

        $("#dataTabs").datagrid('load', formData);
    }



    /*账号状态设置--start*/
    $("#status").click(function () {
        var flag = $("#dataTabs").datagrid('getChecked');
        if (flag.length == 0 ) {
            $.messager.alert("账号状态修改", "至少选择一条数据", "info")
            return false
        }else  if (flag.length > 1){
            $.messager.alert("账号状态修改", "一次只能操作一条数据", "info")
            $("#dataTabs").datagrid('clearChecked');
            return false
        }

        var married = flag[0]

        if (married.status == 0) {
            $.messager.confirm('禁用启用账号', '您是否确定审核通过该账号,该状态时候不可登录，不可下单', function (r) {
                if (r) {
                    comfimStatus()
                }
            })
        }
        if (married.status == 1) {
            $.messager.confirm('禁用启用账号', '您是否确定恢复该账号,该状态时候不可登录，不可下单', function (r) {
                if (r) {
                    comfimStatus()
                }
            })
        }
        if (married.status == 2) {
            $.messager.confirm('禁用启用账号', '您是否确定禁用该账号', function (r) {
                if (r) {
                    comfimStatus()
                }
            })
        }


    })

    function comfimStatus() {
        var flag = $("#dataTabs").datagrid('getChecked');
        var married = flag[0]
        $.post("married/changeStatus.do?", {status: married.status, pid: married.pid}, function (data) {
            if (data) {
                //刷新页面
                $("#dataTabs").datagrid('reload');
                $.messager.alert('禁用启用账号', '修改账号状态成功', 'info')
            } else {
                //刷新页面
                $("#dataTabs").datagrid('reload');
                $.messager.alert('禁用启用账号', '修改账号状态失败', 'info')
            }
        })
    }

    /*账号状态设置--end*/

    /*添加账号 --start*/
    $("#marriedAdd").click(function () {
        $("#addMarriedWindow").window({
            closed: false
        })
    })

    function insertMarried() {
        $("#marriedForm").form('submit', {
            url:'married/saveOrUpdate.do',
            onSubmit: function () {
                var flag = $('#marriedForm').form('validate');
                return flag;
            },
            success: function (data) {
                if (data) {
                    $('#addMarriedWindow').window({
                        closed: true
                    });
                    //清除表单
                    $("#marriedForm").form('reset');
                    //刷新页面
                    $("#dataTabs").datagrid('reload');
                    $.messager.alert('温馨提示', '操作账号成功', 'info')
                } else {
                    $('#addMarriedWindow').window({
                        closed: true
                    });
                    //清除表单
                    $("#marriedForm").form('reset');
                    //刷新页面
                    $("#dataTabs").datagrid('reload');
                    $.messager.alert('温馨提示', '操作账号失败', 'info')
                }
            }
        });
    }
    /*添加账号 --end*/

    /*编辑账号 --start*/
    $("#editMarried").click(function () {
        var check= $("#dataTabs").datagrid('getChecked');

        if (check.length == 0) {
            $.messager.alert("编辑账号","至少选择一条数据","info")
            return false
        }else if( check.length > 1){
            $.messager.alert("编辑账号","一次只能操作一条数据","info")
            $("#dataTabs").datagrid('clearChecked');
            return false

        }

        var married=check[0]
        console.log(married)

        $("#addMarriedWindow").window({
            closed:false
        })

        married.ppwd=null
        //回显数据
        $('#marriedForm').form('load',married);


    })
    /*编辑账号 --end*/

    /*删除账号 -- start*/
    $("#delMarried").click(function () {
        //获取选择的id
        var check = $("#dataTabs").datagrid("getChecked");

        if (check.length == 0) {
            $.messager.alert("删除账号", "至少选择一条数据", "info")
            return false
        }

        var pids = []

        $.each(check, function (index, married) {
            pids.push(married.pid)
        })

        $.messager.confirm('删除账号', '你确定要删除选中的删除账号吗?', function(r){
            if (r){
                $.get("married/deleteMarried.do?pids=" + pids, function (data) {
                    if (data){
                        $("#dataTabs").datagrid('reload');
                        $.messager.alert('删除账号', '删除成功', 'info')
                    }else {
                        $("#dataTabs").datagrid('reload');
                        $.messager.alert('删除账号', '删除失败', 'info')
                    }
                })
            }
        });

    })
    /*删除账号 -- end*/

</script>
</body>
</html>
